<%@ page language="java" contentType="text/html"
    pageEncoding="utf-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>用户注册页面</title>
<%
 //response.setCharacterEncoding("GBK"); 
 //request.setCharacterEncoding("GBK");
%>
<script type="text/javascript">
function showuser() {
	var xmlhttp;
	if (window.XMLHttpRequest) {// code for IE7+, Firefox, Chrome, Opera, Safari
		xmlhttp = new XMLHttpRequest();
	} else {// code for IE6, IE5
		xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
	}
	xmlhttp.onreadystatechange = function() {
		if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
			document.getElementById("myDiv").innerHTML = xmlhttp.responseText;
		}
	}
	xmlhttp.open("post", "existUserName.action?userName="
			+ document.getElementById("user.ofName").value, true);
	xmlhttp.send();

}

function checkRegister() {
	var username = document.getElementById("user.ofName").value;
	var password = document.getElementById("user.ofPassword").value;
	var password2 = document.getElementById("user.ofPassword2").value;
	var divContext = document.getElementById("myDiv").innerHTML;
	//	alert(divContext);
	var result = true;
	if (username.toString().length < 3) {
		alert("用户名不能小于三位");
		result = false;
	} else if (password.toString().length < 6) {
		alert("密码长度不能小于6位");
		result = false;
	} else if (password != password2) {
		alert("两次密码输入不一致，请重新输入");
		result = false;
	}else if(divContext == "该用户已经存在！请改换用户名.."){
		result = false;
	}
	return result;
}
</script>
	</head>
<body bgcolor="#FAFBE7">
	<center>
	<form action="userRegister.action" method="post">
	<table>
		<tr>
			<td>用户名：</td>
			<td><input type="text" name="user.ofName" id="user.ofName" onblur="showuser()"/></td>
			<td><div id="myDiv" style="color: red"></div></td>
		</tr>
		<tr>
			<td>密码：</td>
			<td colspan="2"><input type="password" name="user.ofPassword" id="user.ofPassword"/></td>
		</tr>
		<tr>
			<td>确认密码:</td>
			<td colspan="2"><input type="password" name="user.ofPassword2" id="user.ofPassword2"/></td>
		</tr>
		<tr>
			<td colspan="3"><input type="submit" value="注册" onclick="return checkRegister()"/>
			<a href="userLogin.jsp">登录</a>
			</td>
		</tr>
	</table>
	</form>
	</center>
</body>
</html>